#ifndef WIDGET_PLAY_H
#define WIDGET_PLAY_H



#include "gui.h"
#include "game.h"

#include <queue>
#include <QtGui>
#include <QObject>
#include <QTimer>



class game_state;

class pre_move_info;
class pre_fire_info;



class map_square: public QGraphicsPixmapItem
{

public:

	map_square( QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );


protected:

	void mousePressEvent( QGraphicsSceneMouseEvent* event );
	void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
	void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );

};



class map_bonus: public QGraphicsPixmapItem
{

public:

	map_bonus( bonus* b, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );


private:

	bonus* bon;

};



class map_unit:public QGraphicsPixmapItem
{

public:

	map_unit( unit* un, QGraphicsItem* parent = 0, QGraphicsScene* scene = 0 );

	void select();
	void unselect();
	void setPixmaps( QPixmap* n, QPixmap* s );
	void setNormalPixmap();
	void setSelectedPixmap();
	void setFireSound( QSound* s );
	void playFireSound();
	void setUnitInfo( QLabel* ui )
	{
		uinfo = ui;
	};

	unit* u;
	QLabel* uinfo;


protected:

	void mousePressEvent( QGraphicsSceneMouseEvent* event );
	void hoverEnterEvent( QGraphicsSceneHoverEvent* event );
	void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );


private:

	QPixmap* normal_pixmap;
	QPixmap* selected_pixmap;
	QSound* fire_sound;

};



class p
{

public:

	p( std::queue< std::pair< unsigned int, unsigned int > >* pth, unsigned int cost );
	p( std::queue< std::pair< unsigned int, unsigned int > >* pth );
	~p();


private:

	std::queue< QGraphicsPixmapItem* > s;
	QGraphicsTextItem* cost_l;
	bool cost_set;
};



class play_widget:public QWidget
{

	Q_OBJECT

public:

	play_widget( QWidget* parent = 0, Qt::WindowFlags flags = 0 );

	void forward_command( player* plr, std::string cmd )
	{
		emit send_command( plr, cmd );
	};

	void create_map();
	void add_bonuses();
	void add_players();
	void update_curr_player_label();
	void update_curr_time_label();
	void update_unit_status( unit* u, QLabel* ul );
	void update_selected_unit_status( unit* u );

	void show_move( unit* u, unsigned int x, unsigned int y, pre_move_info* pmi );
	void show_fire( unit* u, unsigned int x, unsigned int y, pre_fire_info* pfi );
	void show_next_turn();
	void set_paused( bool paused );


	QVBoxLayout* layout;


	QLabel* selected_unit_status_l;

	
	QLabel* current_player_l;
	QLabel* current_time_l;


	QGraphicsScene* gs;
	map_unit* selected_unit;
	player* current_player;
	array2d< map_square* >* map_array;
	p* path;
	p* remote_path;
	QGraphicsLineItem* fire_line;
	QGraphicsLineItem* remote_fire_line;

	QPushButton* next_b;
	QPushButton* next_ai_command_b;
	QPushButton* pause_b;


signals:

	void send_command( player*, std::string );


protected slots:

	void delete_remote_path();
	void delete_remote_fire_line();
	void show_estimated_places();
	void show_dangerous_places();
	void show_dangerous_places_nobody();
	void show_attackable_places();
	void show_game_state_score();
	void next();
	void next_ai_command();
	void ai_pause();
	void save_game();


private:

	QWidget* create_map_widget( array2d< unsigned int >* map );

};



#endif